import os
import rtconfig
from building import *

Import('SDK_LIB')

objs = []
cwd = GetCurrentDir()
list = os.listdir(cwd)

# add general drivers
src = Split('''
board.c
''')

if GetDepend(['BSP_USING_SPI3_SAMPLE']):
    src += Glob('ports/spi_sample.c')

if GetDepend(['BSP_USING_RW007']):
    src += Glob('ports/drv_rw007.c')

if GetDepend(['BSP_USING_CYW43012_WIFI']):
    src += Glob('ports/drv_cyw43012.c')

if GetDepend(['BSP_USING_SLIDER_SAMPLE']):
    src += Glob('ports/slider_sample.c')

path = [cwd]
path += [cwd + '/ports']

startup_path_prefix = SDK_LIB

if rtconfig.PLATFORM in ['gcc']:
    src += [startup_path_prefix +
            '/IFX_PSOC6_HAL/mtb-pdl-cat1/drivers/source/TOOLCHAIN_GCC_ARM/cy_syslib_ext.S']
elif rtconfig.PLATFORM in ['armclang']:
    src += [startup_path_prefix +
            '/IFX_PSOC6_HAL/mtb-pdl-cat1/drivers/source/TOOLCHAIN_ARM/cy_syslib_ext.S']

CPPDEFINES = ['CY8C624ALQI_S2D42', 'CORE_NAME_CM0P_0', 'CORE_NAME_CM4_0', 'CY_USING_PREBUILT_CM0P_IMAGE', 'CY_USING_HAL', 'COMPONENT_CAT1A', 'COMPONENT_CAT1']

if GetDepend(['BSP_USING_CYW43012_WIFI']):
    CPPDEFINES += [
        "COMPONENT_WIFI_INTERFACE_SDIO",
        "CYBSP_WIFI_CAPABLE",
        "CY_RTOS_AWARE",
        "CY_SUPPORTS_DEVICE_VALIDATION",
        ]
if GetDepend(['BSP_USING_CYW43012_BT']):
    CPPDEFINES += [
        "COMPONENT_43012",
        "COMPONENT_APP_CY8CKIT_062S2_43012",
        "COMPONENT_AW_AM497",
        "COMPONENT_CAT1",
        "COMPONENT_CAT1A",
        "COMPONENT_CM0P_SLEEP",
        "COMPONENT_CM4",
        "COMPONENT_CM4_0",
        "COMPONENT_Debug",
        "COMPONENT_FREERTOS",
        "COMPONENT_GCC_ARM",
        "COMPONENT_HCI_UART",
        "COMPONENT_MW_ABSTRACTION_RTOS",
        "COMPONENT_MW_BTSTACK",
        "COMPONENT_MW_BTSTACK_INTEGRATION",
        "COMPONENT_MW_CLIB_SUPPORT",
        "COMPONENT_MW_CMSIS",
        "COMPONENT_MW_CORE_LIB",
        "COMPONENT_MW_CORE_MAKE",
        "COMPONENT_MW_FREERTOS",
        "COMPONENT_MW_KV_STORE",
        "COMPONENT_MW_MTB_HAL_CAT1",
        "COMPONENT_MW_MTB_PDL_CAT1",
        "COMPONENT_MW_RECIPE_MAKE_CAT1A",
        "COMPONENT_MW_RETARGET_IO",
        "COMPONENT_MW_SERIAL_FLASH",
        "COMPONENT_PSOC6_02",
        "COMPONENT_WICED_BLE",
        "COMPONENT_WIFI_INTERFACE_SDIO",
        "CY8C624ALQI_S2D42",
        "CY_APPNAME_mtb_example_btstack_freertos_hello_sensor",
        "CY_RETARGET_IO_CONVERT_LF_TO_CRLF",
        "CY_RTOS_AWARE",
        "CY_SUPPORTS_DEVICE_VALIDATION",
        "CY_TARGET_BOARD=APP_CY8CKIT_062S2_43012",
        "CY_USING_HAL",
        "TARGET_APP_CY8CKIT_062S2_43012",
        "USE_INTERNAL_FLASH"
        ]
group = DefineGroup('Drivers', src, depend=[''], CPPPATH=path, CPPDEFINES=CPPDEFINES)

Return('group')
